/*
 * Event service object based on com.nokia.device.event Interface
 */
var so = null;

/*
 * Initializes event service object
 */
function initEvents(){
    try {
        so = nokia.device.load("commlog");
    } 
    catch (e) {
        alert(e);
    }
}

/*
 * Gets list of events based on filter
 * See createFilter() for details
 */
function GetEvents(filter){
    try {
        transaction_id = so.getList(onGetEventsNotification, filter, onGetEventsNotificationErr);
    } 
    catch (e) {
        alert(e);
    }
}

/*
 This is callback function for Events API getList ( callback,[match] ) function
 An iterator object consisting of objects containing the matching events data is further
 passed to the display events function located in basic.js.
 Event data item schema:
 {
 "type": String,     // One of "SMS", "Call"
 "time": String,     // Event Time.Eg: "Wednesday,  25 February, 2009 12:38:05 pm"
 "phoneNumber": String,
 "flag": String,     // One of "Incoming", "Outgoing", "Received", "Missed"
 "summary": String
 }
 */
function onGetEventsNotification(iter){
	try {
            DisplayEvents(iter);
    } 
    catch (e) {
        alert(e);
    }
    
}

/*
 * Error callback handler for getList
 */
function onGetEventsNotificationErr(err){
    alert(err.toString());
}
/*
 * This function returns filter object for get event calls
 Event Matching Pattern
 {
 "type": String,    // Optional.One of  "SMS", "Call".
 "flag": String     // Optional.One of "Outgoing", "Received", "Missed"
 "nofLogs": Integer, // Optional.Limits filter to maximum number of logs to retrieve
 "phone": String    // Optional.Phone number
 }
 */
function createFilter(ftype, fflag, fnofLogs, fphone){
    try {
        var filter = {
            type: ftype,
            flag: fflag,
            nofLogs: fnofLogs,
            phoneNumber: fphone,
        };
        return filter;
    } 
    catch (e) {
        alert(e);
    }
}